package zdream.pmfield.test.stage.battle;

import org.junit.Before;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.FromDataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;

import zdream.pmfield.data.foe.Foe;
import zdream.pmfield.data.foe.FoeTemplate;
import zdream.pmfield.data.foe.MoveTemplate;
import zdream.pmfield.stage.Stage;
import zdream.pmfield.storage.FoeTemplateStorage;
import zdream.pmfield.stage.StageWrapper;
import static org.junit.Assume.*;
import static org.junit.Assert.*;

/**
 * @author Zdream
 * @date 2023-11-23
 * @since 0.0.1
 */
@RunWith(Theories.class)
public class Simple1v1TheoryCase {
	FoeTemplateStorage storage;

	@DataPoints("foe-id")
	public static int[] foeIds() {
		int[] results = new int[30];
		for (int i = 0; i < results.length; i++) {
			results[i] = i;
		}
		return results;
	}

	@DataPoints("move-id")
	public static int[] moveIds() {
		int[] results = new int[2];
		for (int i = 0; i < results.length; i++) {
			results[i] = i;
		}
		return results;
	}

	@Before
	public void before() {
		storage = new FoeTemplateStorage();
		storage.load();
	}

	@Theory
	public void test1v1(
			@FromDataPoints("foe-id") int foe1Id,
			@FromDataPoints("foe-id") int foe2Id,
			@FromDataPoints("move-id") int move1Id,
			@FromDataPoints("move-id") int move2Id) {

		MoveTemplate move1 = storage.findMoveById(move1Id, 1);
		assumeNotNull(move1);

		MoveTemplate move2 = storage.findMoveById(move2Id, 1);
		assumeNotNull(move2);

		FoeTemplate foeTemplate1 = storage.findFoeById(foe1Id);
		assumeNotNull(foeTemplate1);

		FoeTemplate foeTemplate2 = storage.findFoeById(foe2Id);
		assumeNotNull(foeTemplate2);

		Foe foe1 = Foe.builder(foeTemplate1)
				.withLevel(20)
				.withMove(move1)
				.skipShuffleVStat()
				.build();
		assertNotNull(foe1);

		Foe foe2 = Foe.builder(foeTemplate2)
				.withLevel(20)
				.withMove(move2)
				.skipShuffleVStat()
				.build();
		assertNotNull(foe2);

		System.out.println("\n\n\n\n===========");
		System.out.println("foe1 = " + foe1);
		System.out.println("move1 = " + move1);
		System.out.println("foe2 = " + foe2);
		System.out.println("move2 = " + move2);

		final Stage stage = Stage.builder()
				.putFoeToOneSide(foe1)
				.putFoeToAnotherSide(foe2)
				.withStorage(storage)
				.build();
		StageWrapper wrapper = StageWrapper.of(stage);
		wrapper.printBeforeHandleMessage();
		wrapper.setMaxMessageCount(500);
		wrapper.onDefaultActionRequest();
		wrapper.run();
	}
}
